import {HIDE_AD} from "./actionTypes";

const initState = [
    {
        id: 1,
        title: '最新的 react 18.0.0上线了',
        imgUrl: 'https://mina.52kfw.cn/uploads/attach/2022/02/20220226/689f59a3250f4ab3a79f50740fe074db.png',
        status: true
    },
    {
        id: 2,
        title: '最好的前端框架是哪个呢？',
        imgUrl: 'https://mina.52kfw.cn/uploads/attach/2022/02/20220226/d66bdb0c7764c3fab53d492d1dfbe94e.png',
        status: true
    },
];

function adReducer(state = initState, action) {
    switch (action.type) {
        case HIDE_AD:
            // 将对应的隐藏
            return state.filter(item => {
                /*filter 返回为 true 的保留，为 false 则过滤*/
                if (item.id == action.id) {
                    return false;
                } else {
                    return true;
                }
            });
            break;
        default:
            return state;
    }
}

export default adReducer;
